<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
       <title>Title</title>
</head>
<body>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
    <h1>获取用户列表</h1>
当前用户: ${USER.username}
<a href="${pageContext.request.contextPath}/user/logout">退出</a>
<form action="/order/1" method="post" id="deleteForm"><input type="hidden" name="_method" value="DELETE"/></form>
<form method="post" action="/order/upload" enctype="multipart/form-data">
    请选择你要上传的文件<br>
    <input type="file" name="file">
    <input type="submit" value="上传">
</form>
<table align="center"  width="60%" border="1px" bordercolor="#FB5832" CELLSPACING="0">
           
    <tr>         
        <td>id</td>       
        <td>订单</td>     
        <td>金额</td>
        <td>样式</td>     
        <td>操作</td>     
    </tr>
         <c:forEach items="${orderList}" var="order">
    <tr>               
        <td>${order.id}</td>         
        <td>${order.code}</td>           
        <td>${order.money}</td>
        <td>
            <img src="${order.picture}" onclick="imgurl('${order.picture}')" style="height: 50px;width: 50px">
        </td>         
        <td>
            <a href="javascript:void(0)" onclick="deleteById(${order.id})">删除</a>
        </td>           
    </tr>
          </c:forEach>
</table>

<center>
            <h3>添加订单</h3>
    <form action="/order/save" method="post">
        <label for="code">订单<input id="code" type="text" name="code"/></label>
        <label for="money">总金额<input id="money" type="text" name="money"/></label>
        <select id="add_select" name="add_select">
            <c:forEach items="${allImg}" var="allImg">
                <option value="${allImg.imgname}">
                        ${allImg.imgname}
                </option>
            </c:forEach>
        </select> 
        <button>添加订单</button>       
    </form>
            <h3>修改订单</h3>
    <form action="/order/update" method="post">
        <label for="upid">ID<input id="upid" type="text" name="id"/></label>
        <label for="upcode">订单<input id="upcode" type="text" name="code"/></label>
        <label for="upmoney">总金额<input id="upmoney" type="text" name="money"/></label>
        <select id="update_select" name="update_select">
            <c:forEach items="${allImg}" var="allImg">
                <option value="${allImg.imgname}">
                        ${allImg.imgname}
                </option>
            </c:forEach>
        </select>  
        <button>修改订单</button>       
    </form>
</center>
   
<script>
    function deleteById(id) {
        //TODO 删除
        var form = document.getElementById("deleteForm");
        form.action = "/order/" + id;
        form.submit();
    }
    function imgurl(picture){
        alert(picture)
        var picturename = picture.split('static/')[1];
        // 通过选择器获取img元素  图片地址，
        var url ="http://localhost:8080/static/"+ picturename;
        // 将图片的src属性作为URL地址
        var a = document.createElement('a');
        var event = new MouseEvent('click');
        a.download = picturename; //下载图片名称  test
        a.href = url;
        //执行下载
        a.dispatchEvent(event);
    }

</script>
</body>
</html>
​
